<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAdminUsersAndAdminRolesAndAdminPermissionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 50)->unique()->comment('用户名');
            $table->string('email')->unique()->comment('邮箱');
            $table->string('password')->comment('密码');
            $table->rememberToken();
            $table->boolean('is_lock')->default(0)->comment('是否锁定');
            $table->string('avatar')->nullable()->default('/admin/assets/img/avatars/divyia.jpg')->comment('头像');
            $table->string('phone', 15)->default(0)->comment('手机号');
            $table->timestamps();
        });

        Schema::create('admin_roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 50)->unique()->comment('名称');
            $table->string('description')->nullable()->comment('描述');
            $table->boolean('status')->default(1)->comment('状态：1 => 启用，0 => 禁用');
            $table->timestamps();
        });

        Schema::create('admin_permissions', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('pid')->default(0)->comment('所属分类');
            $table->string('title', 50)->comment('名称');
            $table->string('name', 50)->unique()->comment('标识');
            $table->boolean('status')->default(1)->comment('状态：1 => 启用，0 => 禁用');
            $table->boolean('type')->default(1)->comment('类型：1 => 菜单，0 => 权限');
            $table->unsignedSmallInteger('sort')->default(200)->comment('排序');
            $table->string('icon', 50)->nullable()->comment('菜单标识');
            $table->timestamps();
        });

        Schema::create('admin_role_users', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->default(0);
            $table->unsignedInteger('role_id')->default(0);
        });

        Schema::create('admin_permission_roles', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('role_id')->default(0);
            $table->unsignedInteger('permission_id')->default(0);
        });

        Schema::create('admin_permission_users', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->default(0);
            $table->unsignedInteger('permission_id')->default(0);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_users');
        Schema::dropIfExists('admin_roles');
        Schema::dropIfExists('admin_permissions');
        Schema::dropIfExists('admin_role_users');
        Schema::dropIfExists('admin_permission_roles');
        Schema::dropIfExists('admin_permission_users');
    }
}
